const express = require('express')
const app = express()
//get 请求
app.get('/server', (request, response) => {
    //设置允许跨域
    response.setHeader('Access-Control-Allow-Origin', '*')
    setTimeout(() => { 
        response.send({ a: 100, b: 200 })
    },3000)
})
//测试post
app.post('/serverPost', (request, response) => {
    response.setHeader('Access-Control-Allow-Origin', '*')
    // response.setHeader('Access-Control-Allow-Origin', '*')
    // response.header('Access-Control-Allow-Origin', '*');
    // response.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept');
    // response.header('Access-Control-Allow-Methods', 'POST,GET,DELETE,PUT');
    setTimeout(() => { 
        response.send({ a: 100, b: 200 })
    },3000)
})
//测试qs
app.post('/qs', (request, response) => {
    response.setHeader('Access-Control-Allow-Origin', '*')
    setTimeout(() => { 
        response.send({ a: 100, b: 200 })
    },3000)
})


//手动取消请求
app.get('/cancelRequst', (request, response) => {
    response.setHeader('Access-Control-Allow-Origin', '*')
    setTimeout(() => {
        response.send('hello')
    }, 30000)
})

//测试fromdata
app.post('/fromData', (request, response) => {
    response.setHeader('Access-Control-Allow-Origin', '*')
    setTimeout(() => { 
        response.send({ a: 100, b: 200 })
    },3000)
})
//取消重复接口
app.get('/testCancel', (request, response) => {
    response.setHeader('Access-Control-Allow-Origin', '*')
    setTimeout(() => { 
        response.send({ a: 100, b: 200 })
    },3000)
})

//超时 重新请求接口
app.get('/testRepetition', (request, response) => {
    response.setHeader('Access-Control-Allow-Origin', '*')
    setTimeout(() => { 
        response.send({ a: 100, b: 200 })
    },3000)
})
app.listen(8000, () => { 
    console.log("启动")
})

